<?php

namespace app\api\controller;


use think\Db;
use addons\epay\library\Service;
use Yansongda\Pay\Pay;
use app\api\controller\My;
use fast\Random;
use think\Cache;


/**
 * 微信方法
 */
class Alipay
{

    /**
     * 转账
     */
    public  function config()
    {

        $config = Service::getConfig('alipay');
        $config['app_id'] = '2021004128604169';
        $config['notify_url'] = '';
        $config['return_url'] = '';
        $config['private_key'] = '';
        $config['ali_public_key'] = '';
        $config['app_cert_public_key'] = '';
        $config['alipay_root_cert'] = '';
        $config['notify_url'] = '';

        return json($config);
        $pay = Pay::alipay($config);
    }
    /**
     * 转账
     * @return string
     */
    public function transfer($out_biz_no = '11111111111', $trans_amount = '0.1', $user = '3052985@qq.com', $name = '杨兵涛')
    {
        $config = Service::getConfig('alipay');
        //  return json($config);
        $ali_public_key = ROOT_PATH . str_replace('/', DS, substr('\addons/epay/certs/alipayCertPublicKey.crt', 1));
        $alipayRootCert = ROOT_PATH . str_replace('/', DS, substr('\addons/epay/certs/alipayRootCert.crt', 1));
        $appCertPublicKey = ROOT_PATH . str_replace('/', DS, substr('\addons/epay/certs/appCertPublicKey.crt', 1));
        $config['app_id'] = '2021004128604169';
        $config['private_key'] = 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCGfZ6nCdYzyyp44DeEeTHke0F98kyneeoz9KXHjiAunrx+MXwwW39uBVwotr9LQQmU8Jem7ipSxrkSF5pT04nFEfETSjZPDSBRmypcupIIeD5QVPk6nmZGKJY5JsobjnGpaOyeGoQav1ClIxl5kIYzHlDbjm1oLvLsYxfB+fExV3s3WB70zl/75xGkUTH3P019TmwJtJX5Z4+SlmQJs8IwPLEOhoF58ap3srf1TRLseJ+pRtJfVkt2aa2SOwseiFRlPsHHC+7XAL+DkipXD1CY/DpKt5j+foP0GWkekKyIaOrHqNpbE5szLy/gsPxdRO+KgTDkEYi7XyZpyPa5s0YPAgMBAAECggEAGnwehDKRtj1qLcep5zKeuqnzKcRPiCOgFX82Lmg0ujmUUR2Z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vjaGFZiwO4AbQ8q+jwPQRmVpmhIUp08kUInINNpbXnwww3mZt8BiuAMf15lR7ip9gwPOYydFA0Ksrs8OTgDcQDMo3kV3zbhTrL';

        $config['ali_public_key'] = $ali_public_key;
        $config['app_cert_public_key'] = $appCertPublicKey;
        $config['alipay_root_cert'] = $alipayRootCert;
        $pay = Pay::alipay($config);
        // $trans_amount = '0.1';
        //$user = '3052985@qq.com';
        //$name = '杨兵涛';
        $arr = [

            'out_biz_no' => $out_biz_no,
            'trans_amount' => round($trans_amount, 2),
            //'subject' => $title,
            'biz_scene' => 'DIRECT_TRANSFER',
            'product_code' => 'TRANS_ACCOUNT_NO_PWD',
            'order_title' => '订单佣金',
            'payee_info' => [
                'identity' => $user,
                'identity_type' => 'ALIPAY_LOGON_ID',
                'name' => $name
            ],
            'business_params' => [
                'payer_show_name_use_alias' => true
            ]
        ];
        //{"code":"10000","msg":"Success","order_id":"20231117020070011500850011734331","out_biz_no":"66666666","pay_fund_order_id":"20231117020070011500850011734331","status":"SUCCESS","trans_date":"2023-11-17 17:21:54"}
        return  $pay->transfer($arr);
    }
    /**
     * 外部提交
     */
    public function submit()
    {

        $out_trade_no = Random::alpha(10);
        $title = "话费充值10元";
        $amount = request()->request('amount', 10);
        $type = 'alipay';
        $method = 'wap';
        $openid = '';




        $params = [
            'type'         => $type,
            'out_trade_no' => $out_trade_no,
            'title'        => $title,
            'amount'       => $amount,
            'method'       => $method,
            'openid'       => $openid,
            'auth_code'    => '',
            'notifyurl'    => '',
            'returnurl'    => '',
        ];
        return Service::submitOrder($params);
    }
}
